/// <reference path="libs/jquery.d.ts" />
define(["require", "exports"], function (require, exports) {
    exports.baseUrl = ".";
    exports.beforeSend = undefined;
    exports.sum = function (_a, _b, completed) {
        var url = exports.baseUrl + "/JsdlServices/DataService?operation=Sum&";
        var data = JSON.stringify(Array.prototype.slice.call(arguments, 0, completed !== undefined ? arguments.length - 1 : arguments.length));
        $.ajax({
            url: url,
            data: data,
            beforeSend: exports.beforeSend,
            type: "post",
            dataType: "html"
        }).done(function (data, textStatus, result) {
            if (completed !== undefined) {
                var d = null;
                try {
                    d = jQuery.parseJSON(data);
                }
                catch (e) {
                    alert("Operation 'sum' failed: \n\n" + result.responseText);
                }
                completed(d, null, result, textStatus);
            }
        }).fail(function (result, textStatus) {
            var exception = null;
            if (result.status >= 400) {
                if (result.responseText != "")
                    try {
                        exception = jQuery.parseJSON(result.responseText);
                    }
                    catch (e) {
                        exception = { code: "error_" + result.status };
                    }
                else
                    exception = { code: "error_" + result.status };
                console.log("JSDL server exception (operation: sum): " + result.responseText);
            }
            else
                alert("Operation 'sum' failed: \n\n" + result.responseText);
            if (completed !== undefined)
                completed(null, exception, result, textStatus);
        });
    };
    exports.getPerson = function (_id, completed) {
        var url = exports.baseUrl + "/JsdlServices/DataService?operation=GetPerson&";
        var data = JSON.stringify(Array.prototype.slice.call(arguments, 0, completed !== undefined ? arguments.length - 1 : arguments.length));
        $.ajax({
            url: url,
            data: data,
            beforeSend: exports.beforeSend,
            type: "post",
            dataType: "html"
        }).done(function (data, textStatus, result) {
            if (completed !== undefined) {
                var d = null;
                try {
                    d = jQuery.parseJSON(data);
                }
                catch (e) {
                    alert("Operation 'getPerson' failed: \n\n" + result.responseText);
                }
                completed(d, null, result, textStatus);
            }
        }).fail(function (result, textStatus) {
            var exception = null;
            if (result.status >= 400) {
                if (result.responseText != "")
                    try {
                        exception = jQuery.parseJSON(result.responseText);
                    }
                    catch (e) {
                        exception = { code: "error_" + result.status };
                    }
                else
                    exception = { code: "error_" + result.status };
                console.log("JSDL server exception (operation: getPerson): " + result.responseText);
            }
            else
                alert("Operation 'getPerson' failed: \n\n" + result.responseText);
            if (completed !== undefined)
                completed(null, exception, result, textStatus);
        });
    };
    exports.updatePerson = function (_person, completed) {
        var url = exports.baseUrl + "/JsdlServices/DataService?operation=UpdatePerson&";
        var data = JSON.stringify(Array.prototype.slice.call(arguments, 0, completed !== undefined ? arguments.length - 1 : arguments.length));
        $.ajax({
            url: url,
            data: data,
            beforeSend: exports.beforeSend,
            type: "post",
            dataType: "html"
        }).done(function (data, textStatus, result) {
            if (completed !== undefined) {
                var d = null;
                try {
                    d = data;
                }
                catch (e) {
                    alert("Operation 'updatePerson' failed: \n\n" + result.responseText);
                }
                completed(d, null, result, textStatus);
            }
        }).fail(function (result, textStatus) {
            var exception = null;
            if (result.status >= 400) {
                if (result.responseText != "")
                    try {
                        exception = jQuery.parseJSON(result.responseText);
                    }
                    catch (e) {
                        exception = { code: "error_" + result.status };
                    }
                else
                    exception = { code: "error_" + result.status };
                console.log("JSDL server exception (operation: updatePerson): " + result.responseText);
            }
            else
                alert("Operation 'updatePerson' failed: \n\n" + result.responseText);
            if (completed !== undefined)
                completed(null, exception, result, textStatus);
        });
    };
});
//# sourceMappingURL=DataService.js.map